﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;
namespace DAO
{
    public class ApplicationsDAO
    {
        public List<aspnet_Application> LayTatCaApplications()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var App = from app in EFashionDB.aspnet_Applications
                      select app;
            return App.ToList();
        }

        public List<aspnet_Application> LayTatCaApplicationsTheoApplicationName(string AppName)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var App = from app in EFashionDB.aspnet_Applications
                      where app.ApplicationName == AppName
                      select app;
            return App.ToList();
        }

        public List<aspnet_Application> LayTatCaApplicationsTheoApplicationID(Guid ID)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var App = from app in EFashionDB.aspnet_Applications
                      where app.ApplicationId == ID
                      select app;
            return App.ToList();
        }

        public void ThemApplication(aspnet_Application App)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.aspnet_Applications.InsertOnSubmit(App);
            EFashionDB.SubmitChanges();
        }

        public void XoaApplicationTheoApplicationID(Guid ID)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var App = from app in EFashionDB.aspnet_Applications
                      where app.ApplicationId == ID
                      select app;

            EFashionDB.aspnet_Applications.DeleteAllOnSubmit(App);
            EFashionDB.SubmitChanges();
        }

        public void CapNhatApplications(Guid ID, string AppName, string LoweredAppName, string Decs)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var App = from app in EFashionDB.aspnet_Applications
                      where app.ApplicationId == ID
                      select app;

            foreach (aspnet_Application Application in App)
            {
                Application.ApplicationName = AppName;
                Application.LoweredApplicationName = LoweredAppName;
                Application.Description = Decs;
            }

            EFashionDB.SubmitChanges();
        }

        
    }
}
